package com.atcjx.controller;

import com.atcjx.MyUtils.ResultFactory;
import com.atcjx.exception.UserException;
import com.atcjx.pojo.Article.ArticleVO;
import com.atcjx.pojo.Result;
import com.atcjx.service.TagServiceImpl;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.naming.Name;
import java.util.HashSet;
import java.util.List;

/**
 * @author admin
 * @version 1.0.0
 * @ClassName TagController.java
 * @Description TODO
 * @createTime 2021年09月21日 17:43:00
 */
@RestController
public class TagController {
    @Autowired
    private TagServiceImpl tagService;

    @ApiOperation("获取所有的标签")
    @GetMapping("/tags")
    public Result getTags() {
        return ResultFactory.successWithData(tagService.getAllTags());
    }

    @ApiOperation("创建一个新的Tag")
    @GetMapping("/createTag/{tag}")
    @ApiImplicitParam(name = "tag",value = "标签名称",required = true,dataType = "String",paramType = "path")
    public Result createTag(
            @PathVariable("tag") String tag) throws UserException {
        return ResultFactory.success(tagService.createTag(tag)) ;
    }

    @ApiOperation("根据名称删除一个标签")
    @GetMapping("/deleteTag/{tag}")
    @ApiImplicitParam(name = "tag",value = "标签名称",required = true,dataType = "String",paramType = "path")
    public Result deleteTag(
            @PathVariable("tag") String tag)  {
        return ResultFactory.success(tagService.delete(tag)) ;
    }
    @ApiOperation("根据主题名称获取到该主题下的所有标签")
    @GetMapping("/getTagsByTheme")
    public Result getTagsByTheme(@ApiParam("主题名称")
                                 @RequestParam(required = true) String themeName){
        List<String> tagsByTheme = tagService.getTagsByTheme(themeName);
        return ResultFactory.successWithData(new HashSet<String>(tagsByTheme));
    }
}
